import 'package:flutter/material.dart';
import 'package:lick_dog/soul.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '舔狗日记',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  _incrementCounter() {
    setState(() {
      _counter < soul.length - 1 ? _counter++ : _counter = 0;
    });
  }

  randomSoul() {
    var soulList = soul[_counter].toString().split("**").toList();
    List<InlineSpan> _childrenList = [];
    List.generate(soulList.length, (index) {
      String soulString = soulList[index];
      _childrenList.add(TextSpan(
        text: soulString,
        style: TextStyle(
          fontSize: 23,
          color: index % 2 == 1 ? Color(0xFFf0a500) : Colors.black,
          fontFamily: "SaoBao",
        ),
      ));
    });

    return TextSpan(text: "", children: _childrenList);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Positioned(
            top: 40,
            left: 0,
            child: Container(
              width: MediaQuery.of(context).size.width,
              child: Center(
                child: Text(
                  "舔狗日记",
                  style: TextStyle(fontFamily: "SaoBao", fontSize: 34),
                ),
              ),
            ),
          ),
          Container(
            padding: EdgeInsets.all(10),
            child: Center(
              child: Text.rich(
                randomSoul(),
                textAlign: TextAlign.center,
                textDirection: TextDirection.ltr,
                // overflow: TextOverflow.ellipsis,
              ),
            ),
          ),
          Positioned(
            bottom: 40,
            left: (MediaQuery.of(context).size.width - 100) / 2,
            child: InkWell(
              onTap: () => {_incrementCounter()},
              child: Container(
                padding: EdgeInsets.all(10),
                decoration: BoxDecoration(
                  color: Color(0xFFf0a500),
                  borderRadius: BorderRadius.circular(20),
                ),
                child: Text(
                  "再舔一天",
                  style: TextStyle(fontFamily: "SaoBao", fontSize: 20),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}

mixin Math {}
